package com.lhn.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 横切关注点
 *
 * @author lhn
 * @date 2022/01/04 17:34
 * @since 1.0.0
 **/
@Component
// 生产代理对象
@Aspect
public class UserProxy {

    /**
     * 前置通知
     * */
    @Before(value = "execution(* com.lhn.spring5.aopanno.User.add(..))")
    public void before() {
        System.out.println("before..........");
    }

    /**
     * 后置通知(最终通知)
     * */
    @After(value = "execution(* com.lhn.spring5.aopanno.User.add(..))")
    public void after() {
        System.out.println("after..........");
    }

    /**
     * 返回通知
     * */
    @AfterReturning(value = "execution(* com.lhn.spring5.aopanno.User.add(..))")
    public void afterReturning() {
        System.out.println("afterReturning..........");
    }

    /**
     * 异常通知
     * */
    @AfterThrowing(value = "execution(* com.lhn.spring5.aopanno.User.add(..))")
    public void afterThrowing() {
        System.out.println("afterThrowing............");
    }

    /**
     * 环绕通知
     * */
    @Around(value = "execution(* com.lhn.spring5.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前.........");
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后.........");
    }
}